package cn.tedu.springmvc.controller.handler;

import cn.tedu.springmvc.vo.UserVO;
import org.springframework.remoting.RemoteTimeoutException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.io.IOException;

@RestControllerAdvice
// @ControllerAdvice
// @ResponseBody
public class GlobalExceptionHandler {

    @ExceptionHandler({NullPointerException.class,
            NumberFormatException.class})
    public String handleException(Throwable e) {
        return "Error, " + e.getClass().getName() + ", message : " + e.getMessage();
    }

    @ExceptionHandler
    public String handleThrowable(Throwable e) {
        e.printStackTrace();
        return "Error, " + e.getClass().getName() + ", message : " + e.getMessage();
    }

    // try {
    //    ???.???(xx);
    // } catch (NullPointerException e) {
    //    handleException(e);
    // } catch (FileNotFoundException e) {
    // } catch (IOException e) {
    // }

}
